package com.kenans.contorller;

import com.kenans.common.JsonResult;
import com.kenans.entity.Car;
import com.kenans.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 分析url可以知道，getid backid 是前端传递过来的，后台应该有一个controller接受参数，根据id查找对应的城市！
 * @author KENANS
 * @date 2020-8-26 17:41
 * @Version 1.0
 */
@RequestMapping("/car")
@Controller
public class CarController {
    @Autowired
    private CarService carService;

    @RequestMapping("/price.do")
    @ResponseBody
    public JsonResult findAllOfPrice(Integer getid) {
        List<Car> cars = carService.findAllOfPrice(getid);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(1);
        jsonResult.setInfo(cars);
        return jsonResult;
    }

    @RequestMapping("/number.do")
    @ResponseBody
    public JsonResult findAllOfNumber(Integer getid) {
        List<Car> cars = carService.findAllOfNumber(getid);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(1);
        jsonResult.setInfo(cars);
        return jsonResult;
    }

    @RequestMapping("/findcar.do")
    @ResponseBody
    public JsonResult fingCar(Integer cid) {
        Car car = carService.findByCid(cid);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setInfo(car);
        jsonResult.setCode(1);
        return jsonResult;
    }

}
